package com.vue3.blog.web;

import cn.dev33.satoken.stp.StpUtil;
import com.vue3.blog.common.resp.Result;
import com.vue3.blog.domain.dto.LoginDTO;
import com.vue3.blog.domain.vo.LoginInfoVO;
import com.vue3.blog.service.ISysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author Mr.小朱同学
 * @version 1.0.0
 * @date 2025/6/30 12:13
 * @description 登录控制器
 */
@RestController
@RequestMapping("/api/user")
public class LoginController {
    @Resource
    private ISysUserService sysUserService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody @Valid LoginDTO dto) {
        return Result.success("登录成功", sysUserService.login(dto));
    }

    @PostMapping("/logout")
    public Result<Void> logout() {
        StpUtil.logout();
        return Result.success("注销成功");
    }

    @GetMapping("/info")
    public Result<LoginInfoVO> getUserInfo() {
        return Result.success("用户信息", sysUserService.getUserInfo());
    }

}